
//
//  String+Extension.swift
//  SwiftLibrary
//
//  Created by user on 16/2/16.
//  Copyright © 2016年 taurusxi. All rights reserved.
//

import Foundation

extension String {

 
  
  // ===============================================================================================
  // MARK:适配函数
  // ===============================================================================================
//  func sizeWithFontCompatible(font:UIFont) ->CGSize {
//    if self.respondsToSelector(Selector("sizeWithAttributes:") {
//      let dictionaryAttributes:NSDictionary = [NSFontAttributeName:font]
//      let stringSize = self.sizeWithAttributes(dictionaryAttributes)
//      return CGSizeMake(ceil(stringSize.Width), ceil(stringSize.height))
//    }
//    else {
//      return self.sizeWithFont(font)
//    }
//  }

  // AES加密

  func AES256ParmEncryptWithKey(_ key: String) -> String? {
    if let nsData = self.data(using: String.Encoding.utf8) {
      let resultData = (nsData as NSData).aes256ParmDecrypt(withKey: key)
      if let result = String.init(data: resultData!, encoding: String.Encoding.utf8) {
        return result
      }
    }
    return nil
  }

  // AES 解密

  func AES256ParmDecryptWithKey(_ key: String) -> String? {
    if let nsData = self.data(using: String.Encoding.utf8) {
      let resultData = (nsData as NSData).aes256ParmEncrypt(withKey: key)
      if let result = String.init(data: resultData!, encoding: String.Encoding.utf8) {
        return result
      }
    }
    return nil
  }
}
